/**   
* @Title: FreeMarkerRender.java
* @Package com.jbeer.framework.web.viewrender
* @author Bieber
* @date 2014年6月3日 上午10:20:07
* @version V1.0   
*/

package com.jbeer.framework.web.viewrender;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jbeer.framework.JBeer;
import com.jbeer.framework.JBeerWeb;
import com.jbeer.framework.exception.RenderingViewException;
import com.jbeer.framework.web.ModelAndView;

import freemarker.template.Template;

/**
* <p>类功能说明:FreemarkerX渲染器</p>
* <p>类修改者	    修改日期</p>
* <p>修改说明</p>
* <p>Title: FreeMarkerRender.java</p>
* @author Bieber <a mailto="bieber.jbeer@hotmail.com">bieber.jbeer@hotmail.com</a>
* @date 2014年6月3日 上午10:20:07
* @version V1.0
*/

public class FreeMarkerRender {
    public static void render(HttpServletRequest request, HttpServletResponse response,
                              ModelAndView modelView) throws RenderingViewException {
        try {
            Template template = JBeerWeb.freemarkerConfig.getTemplate(modelView.getView()+JBeerWeb.viewSuffix, JBeer.applicationEncode);
            PrintWriter writer = response.getWriter();
            template.process(modelView.getDatas(), writer);
            writer.flush();
            writer.close();
        } catch (Exception e) {
            throw new RenderingViewException(e);
        }
    }
}
